<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商家id" prop="businessId">
        <el-input
          v-model="queryParams.businessId"
          placeholder="请输入商家id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="银行卡预留手机号码" prop="bankPhone">
        <el-input
          v-model="queryParams.bankPhone"
          placeholder="请输入银行卡预留手机号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="营业执照图片" prop="businessLicense">
        <el-input
          v-model="queryParams.businessLicense"
          placeholder="请输入营业执照图片"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业固定电话" prop="telephone">
        <el-input
          v-model="queryParams.telephone"
          placeholder="请输入企业固定电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态 0=未审核 1= 审核通过 2=审核未通过 " prop="stauts">
        <el-input
          v-model="queryParams.stauts"
          placeholder="请输入审核状态 0=未审核 1= 审核通过 2=审核未通过 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核失败原因" prop="failureReason">
        <el-input
          v-model="queryParams.failureReason"
          placeholder="请输入审核失败原因"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提交时间" prop="submissionTime">
        <el-date-picker clearable
          v-model="queryParams.submissionTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择提交时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:certification:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:certification:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:certification:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:certification:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="certificationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="商家id" align="center" prop="businessId" />
      <el-table-column label="银行卡号" align="center" prop="bankCard" />
      <el-table-column label="银行卡银行" align="center" prop="bankType" />
      <el-table-column label="银行卡预留手机号码" align="center" prop="bankPhone" />
      <el-table-column label="企业代码" align="center" prop="enterpriseCode" />
      <el-table-column label="营业执照图片" align="center" prop="businessLicense" />
      <el-table-column label="企业固定电话" align="center" prop="telephone" />
      <el-table-column label="审核状态 0=未审核 1= 审核通过 2=审核未通过 " align="center" prop="stauts" />
      <el-table-column label="审核失败原因" align="center" prop="failureReason" />
      <el-table-column label="提交时间" align="center" prop="submissionTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.submissionTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:certification:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:certification:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商家企业认证对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商家id" prop="businessId">
          <el-input v-model="form.businessId" placeholder="请输入商家id" />
        </el-form-item>
        <el-form-item label="银行卡号" prop="bankCard">
          <el-input v-model="form.bankCard" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="银行卡银行" prop="bankType">
          <el-input v-model="form.bankType" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="银行卡预留手机号码" prop="bankPhone">
          <el-input v-model="form.bankPhone" placeholder="请输入银行卡预留手机号码" />
        </el-form-item>
        <el-form-item label="企业代码" prop="enterpriseCode">
          <el-input v-model="form.enterpriseCode" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="营业执照图片" prop="businessLicense">
          <el-input v-model="form.businessLicense" placeholder="请输入营业执照图片" />
        </el-form-item>
        <el-form-item label="企业固定电话" prop="telephone">
          <el-input v-model="form.telephone" placeholder="请输入企业固定电话" />
        </el-form-item>
        <el-form-item label="审核状态 0=未审核 1= 审核通过 2=审核未通过 " prop="stauts">
          <el-input v-model="form.stauts" placeholder="请输入审核状态 0=未审核 1= 审核通过 2=审核未通过 " />
        </el-form-item>
        <el-form-item label="审核失败原因" prop="failureReason">
          <el-input v-model="form.failureReason" placeholder="请输入审核失败原因" />
        </el-form-item>
        <el-form-item label="提交时间" prop="submissionTime">
          <el-date-picker clearable
            v-model="form.submissionTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择提交时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCertification, getCertification, delCertification, addCertification, updateCertification } from "@/api/system/certification";

export default {
  name: "Certification",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商家企业认证表格数据
      certificationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        businessId: null,
        bankCard: null,
        bankType: null,
        bankPhone: null,
        enterpriseCode: null,
        businessLicense: null,
        telephone: null,
        stauts: null,
        failureReason: null,
        submissionTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        businessId: [
          { required: true, message: "商家id不能为空", trigger: "blur" }
        ],
        bankCard: [
          { required: true, message: "银行卡号不能为空", trigger: "blur" }
        ],
        bankType: [
          { required: true, message: "银行卡银行不能为空", trigger: "change" }
        ],
        bankPhone: [
          { required: true, message: "银行卡预留手机号码不能为空", trigger: "blur" }
        ],
        enterpriseCode: [
          { required: true, message: "企业代码不能为空", trigger: "blur" }
        ],
        businessLicense: [
          { required: true, message: "营业执照图片不能为空", trigger: "blur" }
        ],
        telephone: [
          { required: true, message: "企业固定电话不能为空", trigger: "blur" }
        ],
        stauts: [
          { required: true, message: "审核状态 0=未审核 1= 审核通过 2=审核未通过 不能为空", trigger: "blur" }
        ],
        failureReason: [
          { required: true, message: "审核失败原因不能为空", trigger: "blur" }
        ],
        delFlag: [
          { required: true, message: "删除标志不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商家企业认证列表 */
    getList() {
      this.loading = true;
      listCertification(this.queryParams).then(response => {
        this.certificationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        businessId: null,
        bankCard: null,
        bankType: null,
        bankPhone: null,
        enterpriseCode: null,
        businessLicense: null,
        telephone: null,
        stauts: null,
        failureReason: null,
        submissionTime: null,
        delFlag: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商家企业认证";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCertification(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商家企业认证";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCertification(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCertification(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除商家企业认证编号为"' + ids + '"的数据项？').then(function() {
        return delCertification(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/certification/export', {
        ...this.queryParams
      }, `certification_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
